<?php
include 'topo.php';
$complemento = '';
if(isset($_POST['filtro']))
{
    $filtro = $_POST['filtro'];

    $complemento = " WHERE nome ILIKE '%$filtro%'";
}

//monto a consulta
$sql = "SELECT * FROM animal".$complemento;
//executo no banco, retornando os registros da tabela
$lista = pg_query($sql);
?>
        <div style="text-align:center;font-family: arial">

            <h2 id='centrar'>Animais</h2>

            <p style="text-align:left">+<a href='animal-cadastrar.php'>Novo Animal</a><br/>

            <form action="animal.php" method="post">
            <input type="text" name="filtro" />
            <input type="submit" value="pesquisar"/>
            </form>
            </p>
           
            </br>

            <table border=1 cellspacing=0 cellpadding=2 bordercolor="#6C7B8B">
                <tr>
                    <th bgcolor="#C1CDCD">ID</th>
                    <th bgcolor="#C1CDCD">Nome</th>
                    <th bgcolor="#C1CDCD">Ações</th>
                </tr>
                <?php
                while($linha= pg_fetch_assoc($lista))
                {
                ?>
                <tr>
                    <td><?php echo $linha["id"]?></td>
                    <td><?php echo $linha["nome"]?></td>
                    <td><a href="animal-alterar.php?id=<?php echo $linha["id"]; ?>">Editar</a> 
                    <a href="animal-excluir-ok.php?id=<?php echo $linha["id"]; ?>">Excluir</a></td>
                </tr>
               <?php
               } 

               ?>
            </table>
        </div>
    </body>
</html>